| Conditions | 5 |
| Total Lines | 27 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | // eslint-disable-next-line no-unused-vars |
||
| 11 | async function apiKeyHandler(req, res, next) { |
||
| 12 | 100 | if (req.path === "/admin/feed") { |
|
| 13 | 2 | return next(); |
|
| 14 | } |
||
| 15 | |||
| 16 | 98 | const apiKey = req.headers['x-api-key']; |
|
| 17 | |||
| 18 | 98 | const apiKeyString = Array.isArray(apiKey) ? apiKey[0] : apiKey; |
|
| 19 | |||
| 20 | 98 | if (!apiKeyString) { |
|
| 21 | 1 | return res.status(401).json({ |
|
| 22 | success: false, |
||
| 23 | message: 'API key is required.' |
||
| 24 | }); |
||
| 25 | } |
||
| 26 | |||
| 27 | 97 | const isValidKey = await apiKeyModel.checkOne(apiKeyString); |
|
| 28 | |||
| 29 | 97 | if (!isValidKey) { |
|
| 30 | 1 | return res.status(401).json({ |
|
| 31 | success: false, |
||
| 32 | message: 'Invalid or missing API key. Access denied.' |
||
| 33 | }); |
||
| 34 | } |
||
| 35 | |||
| 36 | 96 | return next(); |
|
| 37 | } |
||
| 38 | |||
| 40 |